package com.cma.util;


import com.cma.generator.bean.Config;
import com.cma.generator.bean.TableInfo;
import com.cma.generator.db.MySQLGenerator;
import com.cma.generator.output.VelocityOutput;
import org.apache.commons.lang.time.DateFormatUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by bjs on 2016/6/20.
 */
public class ExceMain {
    public static void main(String args[]) {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext(new String[]{"applicationContext.xml"});

        List<String> tableList = new ArrayList<String>();
      /*  tableList.add("chntpcloneclassinfo");
        tableList.add("sys_department");
        tableList.add("histcbasic");
        tableList.add("histclanding");
        tableList.add("histctrack");
        tableList.add("historydeclination");
        tableList.add("tcdisaster");
        tableList.add("tcname");
        tableList.add("tcrealtime");
        tableList.add("tfcitydictionary");
        tableList.add("tfcountydictionary");
        tableList.add("tflandinginfo");
        tableList.add("tflandingtrend");*/
        /*  tableList.add("sys_department");*/
         tableList.add("sys_dictionary");
        tableList.add("sys_dictionary_category");
        tableList.add("sys_role");
        tableList.add("sys_user");
        tableList.add("sys_user_role");
        for (String tableName : tableList) {
            doOneTable(tableName);
        }
    }

    private static void doOneTable(String tableName) {


        TableInfo tableInfo = MySQLGenerator.getTableInfo(tableName);
        MySQLGenerator.getColumnList(tableInfo);


        Config config = new Config();

        config.setAuthor("hbb");
        config.setCreateGeneratorTime(DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));

        config.setEntityPkg("com.cma.model.db");
        config.setDaoPkg("com.cma.dao");
        config.setServicePkg("com.cma.service");
//        config.setControllerPkg("com.cma.mall.web.controller");
//        config.setVmTemplatePath("mall");
//        config.setUrlPrefix("");


//        config.setOutputPath("/Users/bain.wang/gen/");


        config.setEntityOutputPath("D:\\mygit\\typhoon\\typhoon-model\\src\\main\\java\\com\\cma\\model\\db\\");
        config.setDaoOutputPath("D:\\mygit\\typhoon\\typhoon-dao\\src\\main\\java\\com\\cma\\dao\\");
        config.setServiceOutputPath("D:\\mygit\\typhoon\\typhoon-service\\src\\main\\java\\com\\cma\\service\\");



        VelocityOutput.execute(tableInfo, config);

    }
}
